install.packages(c("tidyverse", "fixest"))
library(tidyverse)
library(fixest)

## Loading data
load("retail_ndeal.RData")
load("farm_ndeal.RData")
load("banks_ndeal.RData")

## TABLE 3 ##
# Column 1
summary(banks_wpa <- feols(I(log(banks+1)) ~ I(log(pc_wpa + 1)) | my_fips + state^year, data = banks_ndeal))
# Column 2
summary(banks_wpa_trends <- feols(I(log(banks+1)) ~ I(log(pc_wpa + 1)) | my_fips + state^year + my_fips[year], data = banks_ndeal))
# Column 3
summary(banks_pwa <- feols(I(log(banks+1)) ~ I(log(pc_pwa + 1)) | my_fips + state^year, data = banks_ndeal))
# Column 4
summary(banks_pwa_trends <- feols(I(log(banks+1)) ~ I(log(pc_pwa + 1)) | my_fips + state^year + my_fips[year], data = banks_ndeal))
# Column 5
summary(banks_pwa_site <- feols(I(log(banks+1)) ~ I(log(pc_pwa_site_labor + 1)) | my_fips + state^year, data = banks_ndeal))
# Column 6
summary(banks_pwa_site_trends <- feols(I(log(banks+1)) ~ I(log(pc_pwa_site_labor + 1)) | my_fips + state^year+ my_fips[year], data = banks_ndeal))

## FIGURE 4 ##
## Model results in Table A4 of the Dataverse appendix 
## Panel A
summary(banks_wpa_event <- feols(I(log(banks+1)) ~ i(year, I(log(pc_wpa_lead + 1))) | my_fips + state^year + my_fips[year], data = banks_ndeal))

year = c(1927:1936)
banks_wpa_lead_coef = banks_wpa_event$coefficients[1:10]
names(banks_wpa_lead_coef) = NULL
banks_wpa_lead_se = c(0.017532, 0.022289, 0.029358, 0.035739, 0.039943,
                      0.048289, 0.056934, 0.061292, 0.070196, 0.077325)
banks_wpa_lead = data.frame(banks_wpa_lead_coef, banks_wpa_lead_se, year) %>%
  mutate(post = case_when(year %in% c(1935, 1936) ~ "Post-Spending",
                          TRUE ~ "Pre-Spending"))

banks_wpa_lead_plot = banks_wpa_lead %>%
  ggplot(aes(x = factor(year), y = banks_wpa_lead_coef, group = post, color = post)) +
  geom_point(position = position_dodge(width = 0.5)) +
  geom_pointrange(aes(ymin = banks_wpa_lead_coef - (banks_wpa_lead_se * 1.96), 
                      ymax = banks_wpa_lead_coef + (banks_wpa_lead_se * 1.96)), 
                  position = position_dodge(width = 0.5)) +
  geom_hline(yintercept = 0, color = "red", linetype = "dashed") +
  scale_color_manual(values = c("blue", "black")) +
  labs(x = "Year",
       y = "Effect of ln(WPA) on ln(Bank Deposits)") +
  theme_bw() +
  theme(legend.position = "bottom",
        legend.title = element_blank(),
        legend.margin = margin(t = -0.3, r = 0, b = 0, l = 0, unit = "cm"),
        panel.grid.major = element_blank(), 
        panel.grid.minor = element_blank(),
        panel.background = element_rect(colour = "black"))

## Panel B
summary(banks_pwa_event <- feols(I(log(banks+1)) ~ i(year, I(log(pc_pwa_lead + 1))) | my_fips + state^year + my_fips[year], data = banks_ndeal))

year = c(1927:1936)
banks_pwa_lead_coef = banks_pwa_event$coefficients[1:10]
names(banks_pwa_lead_coef) = NULL
banks_pwa_lead_se = c(0.006490, 0.011138, 0.015832, 0.021373, 0.027411,
                      0.032849, 0.039085, 0.042588, 0.047556, 0.052349)
banks_pwa_lead = data.frame(banks_pwa_lead_coef, banks_pwa_lead_se, year) %>%
  mutate(post = case_when(year %in% c(1933, 1934, 1935, 1936) ~ "Post-Spending",
                          TRUE ~ "Pre-Spending"))

banks_pwa_lead_plot = banks_pwa_lead %>%
  ggplot(aes(x = factor(year), y = banks_pwa_lead_coef, group = post, color = post)) +
  geom_point(position = position_dodge(width = 0.5)) +
  geom_pointrange(aes(ymin = banks_pwa_lead_coef - (banks_pwa_lead_se * 1.96), 
                      ymax = banks_pwa_lead_coef + (banks_pwa_lead_se * 1.96)), 
                  position = position_dodge(width = 0.5)) +
  geom_hline(yintercept = 0, color = "red", linetype = "dashed") +
  geom_vline(xintercept = 0, color = "gray", linetype = "dashed") +
  scale_color_manual(values = c("blue", "black")) +
  labs(x = "Year",
       y = "Effect of ln(PWA) on ln(Bank Deposits)") +
  theme_bw() +
  theme(legend.position = "bottom",
        legend.title = element_blank(),
        legend.margin = margin(t = -0.3, r = 0, b = 0, l = 0, unit = "cm"),
        panel.grid.major = element_blank(), 
        panel.grid.minor = element_blank(),
        panel.background = element_rect(colour = "black"))

## TABLE A14 ##
# Column 1
summary(retail_wpa <- feols(I(log(retail+1)) ~ I(log(pc_wpa + 1)) | my_fips + state^year, data = retail_ndeal))
# Column 2
summary(retail_wpa_trends <- feols(I(log(retail+1)) ~ I(log(pc_wpa + 1)) | my_fips + state^year + my_fips[year], data = retail_ndeal))
# Column 3
summary(retail_pwa <- feols(I(log(retail+1)) ~ I(log(pc_pwa + 1)) | my_fips + state^year, data = retail_ndeal))
# Column 4
summary(retail_pwa_trends <- feols(I(log(retail+1)) ~ I(log(pc_pwa + 1)) | my_fips + state^year + my_fips[year], data = retail_ndeal))
# Column 5
summary(retail_pwa_site <- feols(I(log(retail+1)) ~ I(log(pc_pwa_site_labor + 1)) | my_fips + state^year, data = retail_ndeal))
# Column 6
summary(retail_pwa_site_trends <- feols(I(log(retail+1)) ~ I(log(pc_pwa_site_labor + 1)) | my_fips + state^year + my_fips[year], data = retail_ndeal))
# Column 7
summary(farm_wpa <- feols(I(log(farm+1)) ~ I(log(pc_wpa + 1)) | my_fips + state^year, data = farm_ndeal))
# Column 8
summary(farm_wpa_trends <- feols(I(log(farm+1)) ~ I(log(pc_wpa + 1)) | my_fips + state^year + my_fips[year], data = farm_ndeal))
# Column 9
summary(farm_pwa <- feols(I(log(farm+1)) ~ I(log(pc_pwa + 1)) | my_fips + state^year, data = farm_ndeal))
# Column 10
summary(farm_pwa_trends <- feols(I(log(farm+1)) ~ I(log(pc_pwa + 1)) | my_fips + state^year + my_fips[year], data = farm_ndeal))
# Column 11
summary(farm_pwa_site <- feols(I(log(farm+1)) ~ I(log(pc_pwa_site_labor + 1)) | my_fips + state^year, data = farm_ndeal))
# Column 12
summary(farm_pwa_site_trends <- feols(I(log(farm+1)) ~ I(log(pc_pwa_site_labor + 1)) | my_fips + state^year + my_fips[year], data = farm_ndeal))


## FIGURE A11 ##
## Model results in Table A5 of the Dataverse appendix 
summary(banks_pwa_event <- feols(I(log(banks+1)) ~ i(year, I(log(pc_pwa_lead + 1))) | my_fips + state^year, data = banks_ndeal))

year = c(1927:1936)
banks_pwa_lead_coef = banks_pwa_event$coefficients[1:10]
names(banks_pwa_lead_coef) = NULL
banks_pwa_lead_se = c(0.004635, 0.005493, 0.007095, 0.008719, 0.010628,
                      0.013412, 0.016585, 0.015250, 0.015868, 0.016649)
banks_pwa_lead = data.frame(banks_pwa_lead_coef, banks_pwa_lead_se, year) %>%
  mutate(post = case_when(year %in% c(1933, 1934, 1935, 1936) ~ "Post-Spending",
                          TRUE ~ "Pre-Spending"))

banks_pwa_lead_plot = banks_pwa_lead %>%
  ggplot(aes(x = factor(year), y = banks_pwa_lead_coef, group = post, color = post)) +
  geom_point(position = position_dodge(width = 0.5)) +
  geom_pointrange(aes(ymin = banks_pwa_lead_coef - (banks_pwa_lead_se * 1.96), 
                      ymax = banks_pwa_lead_coef + (banks_pwa_lead_se * 1.96)), 
                  position = position_dodge(width = 0.5)) +
  geom_hline(yintercept = 0, color = "red", linetype = "dashed") +
  scale_color_manual(values = c("blue", "black")) +
  labs(x = "Year",
       y = "Effect of ln(PWA) on ln(Bank Deposits)") +
  theme_bw() +
  theme(legend.position = "bottom",
        legend.title = element_blank(),
        legend.margin = margin(t = -0.3, r = 0, b = 0, l = 0, unit = "cm"),
        panel.grid.major = element_blank(), 
        panel.grid.minor = element_blank(),
        panel.background = element_rect(colour = "black"))

